package Easy最佳时机;

import org.testng.annotations.Test;

public class Solution {
    public int maxProfit(int[] prices) {
        if (prices.length<=1)
            return 0;
        int min = prices[0], max = 0;
        for(int i = 1; i < prices.length; i++) {
            max = Math.max(max, prices[i] - min);
            min = Math.min(min, prices[i]);
        }
        return max;
    }
    @Test
    public void test(){
        int[] a = {2,1,4};
        System.out.println(maxProfit(a));
    }
}
